package com.powerhua.core.utils;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

/**
 * 
 * @author brian
 *
 */
public class FileContentUtils {

    /**
     * 获取文本文件内容
     * @param filePath
     * @return
     */
    public static String getTextFileString(String filePath, String coding) {
        StringBuffer sb = new StringBuffer();
        BufferedReader reader;
        try {
            reader = new BufferedReader(new InputStreamReader(
                    new FileInputStream(filePath), coding));
            String tempStr;
            while ((tempStr = reader.readLine()) != null) {
                sb.append(tempStr);
                sb.append(System.getProperty("line.separator"));
            }
            reader.close();
        } catch (UnsupportedEncodingException e) {
            // TODO 
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            // TODO 
            e.printStackTrace();
        } catch (IOException e) {
            // TODO
            e.printStackTrace();
        }

        // return
        return sb.toString();
    }
}
